<template>
  <div class="cityCheckRandom">
    <el-form :inline="true" :model="form" label-width="90px">
      <div class="maintitle">专家现场抽查确认</div>
      <div class="formcontent">
        <div class="basicInformation">
          <span>抽查时间：{{form.surveyTime}}</span>
        </div>
        <div>
          <el-form-item label="抽查工作人员" label-width="124px">
            <el-input :disabled="disabled" v-model="form.workPersonnel" style="width:200px;"></el-input>
          </el-form-item>
          <el-form-item label="专家组成员" label-width="100px">
            <el-input :disabled="disabled" v-model="form.member" style="width:200px;"></el-input>
          </el-form-item>
          <el-form-item label="专家组组长" label-width="112px">
            <el-input :disabled="disabled" v-model="form.leader" style="width:200px;"></el-input>
          </el-form-item>
        </div>
        <div class="maintitle" style="margin:30px 0 20px 0">现场复核意见</div>
        <el-form-item>
          <el-input
            :disabled="disabled"
            type="textarea"
            :rows="6"
            placeholder
            v-model="form.conclusion"
            style="width:1000px;"
          ></el-input>
        </el-form-item>
        <div class="maintitle" style="margin:40px 0 20px 0;">相关附件</div>

        <el-form-item label="耕地质量等别专家复核确认表模板" label-width="222px">
          <el-button :disabled="disabled" @click="handleDownloadTemp" size="small">下载</el-button>
        </el-form-item>
        <div>
          <el-form-item label="耕地质量等别专家复核确认表" label-width="195px">
            <el-upload
              accept=".pdf"
              :disabled="disabled"
              :action="uploadUrl"
              :file-list="fileList[0]"
              :on-success="handleUploadSuccess"
            >
              <el-button v-if="!disabled" size="small" type="primary">上传</el-button>
              <el-button @click="seePdf(0)" v-if="disabled" size="small" type="primary">查看</el-button>
            </el-upload>
          </el-form-item>
        </div>
      </div>
      <div style="margin-top:30px;">
        <el-form-item>
          <el-button v-if="!disabled" @click="addRevice" type="primary">提交</el-button>
          <el-button v-if="!disabled">取消</el-button>
          <el-button v-if="disabled" @click="back">取消</el-button>
        </el-form-item>
      </div>
    </el-form>
    <el-dialog :close-on-click-modal="false" :title="pdfName" :visible.sync="pdfFlag" width="50%">
      <div class="pdfBox">
        <iframe :src="$https + pdfUrl" style="width:100%;height:600px;" frameborder="0"></iframe>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import config from "@/config/index.js";
import {
  getInvAndCon,
  addReview
} from "@/api/completionAcceptance/cityCheckOpinion.js";
import { getFile } from "@/api/completionAcceptance/acceptance";
export default {
  data() {
    return {
      uploadUrl: config.uploadUrl,
      form: {
        flag: 1,
        projectId: localStorage.getItem("projectId"),
        conclusion: "",
        surveyTime: "",
        workPersonnel: "",
        member: "",
        leader: "",
        conclusion: "",
        expertReviewTable: ""
      },
      disabled: true,
      projectId: localStorage.getItem("projectId") || "",
      fileList: [],
      pdfUrl: "",
      pdfFlag: false,
      pdfName: ""
    };
  },

  created() {
    if (this.$route.name === localStorage.getItem("key")) {
      this.disabled = false;
    }
    if (localStorage.getItem("lookStatus") == 2) {
      this.disabled = false;
    }
    this.getReview();
  },
  methods: {
    //查看当前PDF
    seePdf(num) {
      this.pdfFlag = true;
      this.pdfUrl = this.fileList[num][0].url;
      this.pdfName = this.fileList[num][0].name;
    },
    back() {
      this.$router.push("/projectManagement/projectImplementation/dealwith");
    },
    getReview() {
      //获取页面信息
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      getInvAndCon({ projectId: this.projectId })
        .then(res => {
          loading.close();
          if (res.data) {
            this.form = res.data;
            if (res.data.expertReviewTable) {
              var data1 = {
                fileId: res.data.expertReviewTable
              };
              getFile(data1).then(res1 => {
                this.fileList = [
                  [{ name: res1.data.fileName, url: res1.data.filePath }]
                ];
              });
            }
          }
        })
        .catch(res => {
          loading.close();
        });
    },
    handleUploadSuccess: function(res, file, fileList) {
      //耕地质量等别专家复核确认表上传成功回调
      this.form.expertReviewTable = res.data.id;
    },
    handleDownloadTemp: function() {
      //下载耕地质量等别专家复核确认表模板
      // this.$message({
      //   message: "文件缺失"
      // });
      let a = document.createElement("a");
      a.href =
        config.baseUrl +
        "/renovation/templatefile/耕地质量等别专家复核确认表.docx";
      a.target = "_blank";
      a.click();
    },
    addRevice() {
      //提交表单
      const loading = this.$loading({
        lock: true,
        text: "Loading",
        spinner: "el-icon-loading",
        background: "rgba(0, 0, 0, 0.7)"
      });
      this.form.flag = 1;
      this.form.projectId = this.projectId;
      addReview(this.form)
        .then(res => {
          loading.close();
          this.$message({
            message: "提交成功！",
            type: "success"
          });
          this.getReview();
          this.$router.push(
            "/projectManagement/projectImplementation/dealwith"
          );
        })
        .catch(res => {
          loading.close();
        });
    }
  }
};
</script>

<style lang="scss" scoped>
.cityCheckRandom {
  padding: 20px;
  min-height: calc(100vh - 154px);
  background-color: #fff;
  .maintitle {
    font-size: 18px;
    font-family: PingFang SC;
    font-weight: bold;
    line-height: 25px;
    color: #4d4d4d;
  }
  .formcontent {
    margin-top: 30px;
    .basicInformation {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      line-height: 20px;
      color: #8c8c8c;
      margin-bottom: 20px;
      span {
        margin-right: 60px;
      }
    }
    .basicInformationitem {
      font-size: 14px;
      font-family: PingFang SC;
      font-weight: 500;
      line-height: 20px;
      color: #8c8c8c;
      float: left;
      width: 251px;
      margin-bottom: 20px;
    }
  }
}
</style>